<!DOCTYPE html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/model/event_set.html">
<link rel="import" href="/tracing/model/model.html">
<link rel="import" href="/tracing/model/thread_slice.html">
<link rel="import" href="/tracing/ui/analysis/multi_thread_slice_sub_view.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  const newSliceEx = tr.c.TestUtils.newSliceEx;
  const newFlowEventEx = tr.c.TestUtils.newFlowEventEx;

  test('instantiate', function() {
    const model = new tr.Model();
    const t53 = model.getOrCreateProcess(52).getOrCreateThread(53);
    t53.sliceGroup.pushSlice(
        newSliceEx({title: 'a', start: 0.0, duration: 0.5,
          type: tr.model.ThreadSlice}));
    t53.sliceGroup.pushSlice(
        newSliceEx({title: 'b', start: 1.0, duration: 2,
          type: tr.model.ThreadSlice}));
    t53.sliceGroup.createSubSlices();

    const selection = new tr.model.EventSet();
    selection.push(t53.sliceGroup.slices[0]);
    selection.push(t53.sliceGroup.slices[1]);

    const viewEl = document.createElement(
        'tr-ui-a-multi-thread-slice-sub-view');
    viewEl.selection = selection;
    this.addHTMLOutput(viewEl);
  });

  test('withFlows', function() {
    const m = tr.c.TestUtils.newModel(function(m) {
      m.p1 = m.getOrCreateProcess(1);

      m.t2 = m.p1.getOrCreateThread(2);
      m.t3 = m.p1.getOrCreateThread(3);
      m.t4 = m.p1.getOrCreateThread(4);

      m.sA = m.t2.sliceGroup.pushSlice(
          newSliceEx({title: 'a', start: 0, end: 5,
            type: tr.model.ThreadSlice}));
      m.sB = m.t3.sliceGroup.pushSlice(
          newSliceEx({title: 'b', start: 10, end: 15,
            type: tr.model.ThreadSlice}));
      m.sC = m.t4.sliceGroup.pushSlice(
          newSliceEx({title: 'c', start: 20, end: 20,
            type: tr.model.ThreadSlice}));

      m.t2.createSubSlices();
      m.t3.createSubSlices();
      m.t4.createSubSlices();

      m.f1 = newFlowEventEx({
        title: 'flowish', start: 0, end: 10,
        startSlice: m.sA,
        endSlice: m.sB
      });
      m.f2 = newFlowEventEx({
        title: 'flowish', start: 15, end: 21,
        startSlice: m.sB,
        endSlice: m.sC
      });
    });

    const selection = new tr.model.EventSet();
    selection.push(m.sA);
    selection.push(m.sB);
    selection.push(m.sC);

    const viewEl = document.createElement(
        'tr-ui-a-multi-thread-slice-sub-view');
    viewEl.selection = selection;
    this.addHTMLOutput(viewEl);
  });
});
</script>
